package com.example.yls.demoa;

import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
private MyView myView;
private Button btn1;
private Button btn2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btn1Event();
        btn2Event();
    }
    private void btn2Event() {
              btn2.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      ValueAnimator animation= ObjectAnimator.ofInt(0,500);
                      animation.setDuration(5000);
                      animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                          @Override
                          public void onAnimationUpdate(ValueAnimator valueAnimator) {
                              int value= (int) valueAnimator.getAnimatedValue();
                              myView.setRadio(value);
                          }
                      });
                      animation.start();
                  }
              });
    }
    private void btn1Event() {
       btn1.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               ValueAnimator animation= ObjectAnimator.ofInt(0,500);
               animation.setDuration(5000);
               animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                   @Override
                   public void onAnimationUpdate(ValueAnimator valueAnimator) {
                       int value= (int) valueAnimator.getAnimatedValue();
                       myView.setCircle(value);
                   }
               });
               animation.start();
           }
       });
    }
    private void initView() {
       myView=findViewById(R.id.myView);
       btn1=findViewById(R.id.btn1);
       btn2=findViewById(R.id.btn2);
    }
}
